/********************************************************************
 *
 *      Filename: Vector3.h
 *   Description: Class for 3D vectors
 *        Author: [kb]ypp
 *    Created at: February 14, 2005
 * Last modified: October 22, 2005
 *
 ********************************************************************/

#ifndef VECTOR3_H
#define VECTOR3_H

//! @brief Class to represent 3D vectors
//!
//! Vector components are float`s.
class vec3 {
public:
	float x, y, z;
	
	// Static entities:
	static const vec3 ZERO; //!< Zero vector
	
	//! @brief Default constructor
	vec3();
	//! @brief Copy-constructor
	vec3( const vec3 &v );
	//! @brief Constructor to initialize the vector with given coordinates
	vec3( float nx, float ny, float nz );
	
	//! @brief Assignment operator
	const vec3& operator=( const vec3 &rv );
	//! @brief Assignment with addition
	const vec3& operator+=( const vec3 &rv );
	//! @brief Assignment with subtraction
	const vec3& operator-=( const vec3 &rv );
	
	//! @brief The negation of a vector (unary '-')
	const vec3 operator-() const;
	//! @brief Componentwise vector addition
	friend const vec3 operator+( const vec3 &lv, const vec3 &rv );
	//! @brief Componentwise vector subtraction
	friend const vec3 operator-( const vec3 &lv, const vec3 &rv );
	//! @brief The product of a scalar and a vector
	friend const vec3 operator*( float k, const vec3 &v );
	friend const vec3 operator*( const vec3 &v, float k );
	//! @brief Equality (with tolerance) check
	friend bool operator==( const vec3 &lv, const vec3 &rv );
	//! @brief Non-equality (with tolerance) check
	friend bool operator!=( const vec3 &lv, const vec3 &rv );
	
	//! @brief Vector normalization
	void normalize();
	//! @brief The length (in other words: norm, magnitude) of a vector
	friend float length( const vec3 &v );
	//! @brief The squared length of a vector
	friend float lengthSq( const vec3 &v );
	//! @brief The dot product (also known as scalar product or inner product)
	friend float dot( const vec3 &lv, const vec3 &rv );
	//! @brief The cross product (also known as vector product)
	friend const vec3 cross( const vec3 &lv, const vec3 &rv );
};

#endif // VECTOR3_H
